<?php

namespace mpend\modules\user\models;

use Yii;

/**
 * 签到查询
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SigninSearch extends \common\models\user\UserSignin {

    /**
     * 签到检测
     *
     * @return array|\yii\data\ActiveDataProvider
     * @throws \common\base\ModelHttpException
     */
    public function search() {
        $model = static::findOrCreate([
            'user_id' => $this->user_id,
        ]);
        return $model->toArray();
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'user_id',
            'amount',
            'serial',
            'max_serial',
            'repairs',
            'first_date' => function () {
                if ($this->created_at) {
                    return date('Y-m-d', $this->created_at);
                }
                return date('Y-m-d');
            },
            'last_date' => function () {
                return $this->last_time ? date('Y-m-d', $this->last_time) : '';
            },
            'month',
            'periods',
            'today'
        ];
    }

}